﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ABDLight
{
    public partial class frmCleanAddress : Form
    {
        public frmCleanAddress()
        {
            InitializeComponent();


            this.Location = new System.Drawing.Point(SystemInformation.PrimaryMonitorSize.Width / 2, 60);
            this.ClientSize = new System.Drawing.Size(SystemInformation.PrimaryMonitorSize.Width / 2, SystemInformation.PrimaryMonitorSize.Height / 4 * 3);
            grdVariant.Grid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.None;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnIsGood_Click(object sender, EventArgs e)
        {
            ((frmClean)this.Owner).IsGood_Click();
        }

        private void btnIsBad_Click(object sender, EventArgs e)
        {
            ((frmClean)this.Owner).IsBad_Click();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //((frmClean)this.Owner).button1_Click(null, null);
            if (textBox15.Text == "") return;
            string AddrNew = textBox15.Text;

            ((frmClean)this.Owner).ChooseAddrClean(AddrNew);

        }

        private void textBox15_TextChanged(object sender, EventArgs e)
        {

        }

        private void grdVariant_Load(object sender, EventArgs e)
        {

        }

        public void OneRowClean(int StartRow,bool SaveResult = true)
        {
            frmClean.cCfg.FuncType = "update";
            ((frmClean)this.Owner).OneRowClean(StartRow, SaveResult);
        }

        private void frmCleanAddress_Activated(object sender, EventArgs e)
        {
            //this.TopMost = true;
        }

        private void textBox22_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                textBox15.Focus();
            }
        }

        private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                textBox15.Focus();
            }
        }

        private void textBox15_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(null, null);
            }
        }

        public void VariantEmptyHide()
        {
            for (int i = 0; i < grdVariant.Grid.Columns.Count; i++ )
            {
                if (grdVariant.Grid.Rows.Count == 0)
                {
                    grdVariant.Grid.Columns[i].Visible = true;
                }
                else
                {
                    int FieldVal = 0;
                    for (int j = 0; j < grdVariant.Grid.Rows.Count; j++ )
                        if (grdVariant.Grid.Rows[j].Cells[i].Value.ToString() == "") 
                            FieldVal++;

                    if (FieldVal == 0)
                            grdVariant.Grid.Columns[i].Visible = true; 
                    else
                        grdVariant.Grid.Columns[i].Visible = false;
                }

            }
        }



    }
}
